import {createRouter, createWebHashHistory} from "vue-router";
import AdminHome from "../views/admin/AdminHome.vue";

const routes = [{
    path: '/',
    redirect: '/login'
},
    {
        path: '/admin',
        redirect: '/admin/empty'
    }, {
        path: "/admin",
        name: "AdminHome",
        component: AdminHome,
        children: [
            {
                path: "empty",
                name: "Empty",
                meta: {
                    title: '登录成功首页',
                    permission: "00"
                },
                component: () => import("../views/admin/Empty.vue")
            },
            {
                path: "/users",
                name: "users",
                meta: {
                    title: '个人中心',
                    permission: "01"
                },
                component: () => import("../views/User.vue")
            },
            {
                path: "roleManagement",
                name: "RoleManagement",
                meta: {
                    title: '角色管理',
                    permission: "11"
                },
                component: () => import("../views/admin/RoleManagement.vue")
            },
            {
                path: "user",
                name: "user",
                meta: {
                    title: '用户管理',
                    permission: "12"
                },
                component: () => import("../views/admin/UserMng.vue")
            }, {
                path: "addUser",
                name: "addUser",
                meta: {
                    title: '用户编辑',
                    permission: "121"
                },
                component: () => import("../views/admin/AddUser.vue")
            },

            {
                path: "permission",
                name: "permission",
                meta: {
                    title: '权限管理',
                    permission: "13"
                },
                component: () => import("../views/admin/Permission.vue")
            },

            {
                path: "college",
                name: "college",
                meta: {
                    title: '学院基本信息管理',
                    permission: "21"
                },
                component: () => import("../views/admin/College.vue")
            }, {
                path: "addCollege",
                name: "addCollege",
                meta: {
                    title: '学院基本信息编辑',
                    permission: "211"
                },
                component: () => import("../views/admin/AddCollege.vue")
            }, {
                path: "major",
                name: "major",
                meta: {
                    title: '专业基本信息管理',
                    permission: "22"
                },
                component: () => import("../views/admin/Major.vue")
            }, {
                path: "addMajor",
                name: "addMajor",
                meta: {
                    title: '专业基本信息编辑',
                    permission: "221"
                },
                component: () => import("../views/admin/AddMajor.vue")
            }, {
                path: "viewClasses",
                name: "viewClasses",
                meta: {
                    title: '查看专业下班级详情',
                    permission: "222"
                },
                component: () => import("../views/admin/ViewClasses.vue")
            },
            {
                path: "class",
                name: "class",
                meta: {
                    title: '班级基本信息管理',
                    permission: "23"
                },
                component: () => import("../views/admin/Classes.vue")
            }, {
                path: "addClass",
                name: "addClass",
                meta: {
                    title: '班级基本信息编辑',
                    permission: "231"
                },
                component: () => import("../views/admin/AddClass.vue")
            },
            {
                path: "new",
                name: "new",
                meta: {
                    title: '新生管理',
                    permission: "24"
                },
                component: () => import("../views/admin/NewMng.vue")
            }, {
                path: "addNew",
                name: "addNew",
                meta: {
                    title: '新生编辑',
                    permission: "241"
                },
                component: () => import("../views/admin/AddNew.vue")
            },
            {
                path: "articleCate",
                name: "articleCate",
                meta: {
                    title: '类别管理',
                    permission: "31"
                },
                component: () => import("../views/admin/ArticleCate.vue")
            }, {
                path: "addArticleCate",
                name: "addArticleCate",
                meta: {
                    title: '类别编辑',
                    permission: "311"
                },
                component: () => import("../views/admin/AddArticleCate.vue")
            },
            {
                path: "notice",
                name: "notice",
                meta: {
                    title: '公告信息管理',
                    permission: "32"
                },
                component: () => import("../views/admin/Notice.vue")
            },
            {
                path: "viewCharts",
                name: "ViewCharts",
                meta: {
                    title: '公告信息编辑',
                    permission: "321"
                },
                component: () => import("../views/admin/ViewCharts.vue")
            },
            {
                path: "schoolCampus",
                name: "SchoolCampus",
                meta: {
                    title: '校园风光管理',
                    permission: "33"
                },
                component: () => import("../views/admin/SchoolCampus.vue")
            },
            {
                path: "addSchoolpit",
                name: "AddSchoolpit",
                meta: {
                    title: '新增校园风光',
                    permission: "331"
                },
                component: () => import("../views/admin/AddSchoolpit.vue")
            },
            {
                path: "article",
                name: "article",
                meta: {
                    title: '发布管理',
                    permission: "34"
                },
                component: () => import("../views/admin/Article.vue")
            },
            {
                path: "addArticle",
                name: "addArticle",
                meta: {
                    title: '发布编辑',
                    permission: "341"
                },
                component: () => import("../views/admin/AddArticle.vue")
            },
            {
                path: "auditScenery",
                name: "AuditScenery",
                meta: {
                    title: '校园风光发布',
                    permission: "342"
                },
                component: () => import("../views/admin/AuditScenery.vue")
            },

            {
                path: "allocateClass",
                name: "allocateClass",
                meta: {
                    title: '分配班级',
                    permission: "41"
                },
                component: () => import("../views/admin/AllocateClass.vue")
            }, {
                path: "dividedIntoClasses",
                name: "dividedIntoClasses",
                meta: {
                    title: '已分班级管理',
                    permission: "42"
                },
                component: () => import("../views/admin/DividedIntoClasses.vue")
            },


            {
                path: "building",
                name: "building",
                meta: {
                    title: '楼栋基本信息管理',
                    permission: "51"
                },
                component: () => import("../views/admin/Building.vue")
            }, {
                path: "addBuilding",
                name: "addBuilding",
                meta: {
                    title: '楼栋楼层基本信息编辑',
                    permission: "511"
                },
                component: () => import("../views/admin/AddBuilding.vue")
            },
            {
                path: "roomBed",
                name: "roomBed",
                meta: {
                    title: '楼层基本信息管理',
                    permission: "52"
                },
                component: () => import("../views/admin/RoomBed.vue")
            },
            {
                path: "addRoom",
                name: "AddRoom",
                meta: {
                    title: '房间管理',
                    permission: "521"
                },
                component: () => import("../views/admin/AddRoom.vue")
            },
            {
                path: "roomEdit",
                name: "RoomEdit",
                meta: {
                    title: '房间列表信息',
                    permission: "5211"
                },
                component: () => import("../views/admin/RoomEdit.vue")
            },
            {
                path: "addRoomEdit",
                name: "AddRoomEdit",
                meta: {
                    title: '房间编辑',
                    permission: "52111"
                },
                component: () => import("../views/admin/AddRoomEdit.vue")
            },
            {
                path: "bedEdit",
                name: "BedEdit",
                meta: {
                    title: '床位信息',
                    permission: "52112"
                },
                component: () => import("../views/admin/BedEdit.vue")
            },
            {
                path: "bedStudent",
                name: "BedStudent",
                meta: {
                    title: '床位列表详情',
                    permission: "53"
                },
                component: () => import("../views/admin/BedStudent.vue")
            },

            {
                path: "distributionBed",
                name: "DistributionBed",
                meta: {
                    title: '分配房间床位',
                    permission: "61"
                },
                component: () => import("../views/admin/DistributionBed.vue")
            }, {
                path: "moveBed",
                name: "MoveBed",
                meta: {
                    title: '微调房间床位',
                    permission: "62"
                },
                component: () => import("../views/admin/MoveBed.vue")
            },
            {
                path: "bedStudent",
                name: "BedStudent",
                meta: {
                    title: '床位列表详情',
                    permission: "63"
                },
                component: () => import("../views/admin/BedStudent.vue")
            },
            {
                path: "reserve",
                name: "reserve",
                meta: {
                    title: '报到审核',
                    permission: "71"
                },
                component: () => import("../views/admin/Reserve.vue")
            },
            {
                path: "failCheck",
                name: "FailCheck",
                meta: {
                    title: '未报到学生/消息通告',
                    permission: "72"
                },
                component: () => import("../views/admin/FailCheck.vue")
            },
            {
                path: "viewReserveContent",
                name: "ViewReserveContent",
                meta: {
                    title: '个人通告查看',
                    permission: "721"
                },
                component: () => import("../views/admin/ViewReserveContent.vue")
            },
            {
                path: "announcements",
                name: "Announcements",
                meta: {
                    title: '待报道通告管理',
                    permission: "73"
                },
                component: () => import("../views/admin/Announcements.vue")
            },

            {
                path: "goods",
                name: "Goods",
                meta: {
                    title: '物资管理',
                    permission: "81"
                },
                component: () => import("../views/admin/Goods.vue")
            },
            {
                path: "addGoods",
                name: "AddGoods",
                meta: {
                    title: '物资编辑',
                    permission: "811"
                },
                component: () => import("../views/admin/AddGoods.vue")
            },
            {
                path: "goodsReceive",
                name: "GoodsReceive",
                meta: {
                    title: '物资申领列表',
                    permission: "82"
                },
                component: () => import("../views/admin/GoodsReceive.vue")
            },
            {
                path: "applyReceive",
                name: "ApplyReceive",
                meta: {
                    title: '物资申领/确认',
                    permission: "83"
                },
                component: () => import("../views/admin/ApplyReceive.vue")
            },
            {
                path: "classStat",
                name: "classStat",
                meta: {
                    title: '新生地域统计',
                    permission: "91"
                },
                component: () => import("../views/admin/ClassStat.vue")
            },
            {
                path: "progress",
                name: "progress",
                meta: {
                    title: '完成进度统计',
                    permission: "92"
                },
                component: () => import("../views/admin/FinishProgress.vue")
            },
            {
                path: "classOverview",
                name: "ClassesOverview",
                meta: {
                    title: '报道统计',
                    permission: "93"
                },
                component: () => import("../views/admin/ClassesOverview.vue")
            },
            //todo  待分配
            {
                path: "stationRecserve",
                name: "StationRecserve",
                meta: {
                    title: '学生报道详情统计',
                    permission: "94"
                },
                component: () => import("../views/admin/StationRecserve.vue")
            },


            {
                path: "materialsNotReceived",
                name: "MaterialsNotReceived",
                meta: {
                    title: '物资未领取统计',
                    permission: "95"
                },
                component: () => import("../views/admin/MaterialsNotReceived.vue")
            },
            {
                path: "myNotReceived",
                name: "MyNotReceived",
                meta: {
                    title: '个人物资未领取详情',
                    permission: "951"
                },
                component: () => import("../views/admin/MyNotReceived.vue")
            },
            {
                path: "baseCharts",
                name: "BaseCharts",
                meta: {
                    title: '统计图',
                    permission: "96"
                },
                component: () => import("../views/admin/BaseCharts.vue")
            },
            //
            {
                path: "rolePermission",
                name: "RolePermission",
                meta: {
                    title: '路由列表维护',
                    permission: "xxxx"
                },
                component: () => import("../views/admin/RolePermission.vue")
            },
            {
                path: "addRolePermission",
                name: "AddRolePermission",
                meta: {
                    title: '路由列表编辑',
                    permission: "xxxxx"
                },
                component: () => import("../views/admin/AddRolePermission.vue")
            },

        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import("../views/Login.vue")
    },

    // {
    // 	path: "/instructor",
    // 	name: "AdminHome",
    // 	component: AdminHome,
    // 	children: [{
    // 			path: "/reserve",
    // 			name: "reserve",
    // 			meta: {
    // 				title: '报到审核',
    // 				permission: "43"
    // 			},
    // 			component: () => import("../views/instructor/Reserve.vue")
    // 		},

    // ]},
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | 迎新管理系统`;
    const role = localStorage.getItem('ms_role');
    const tokenStr = localStorage.getItem("token");
    if (!role && to.path !== '/login' && !tokenStr) {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        // role === to.meta.permission
        //     ? next()
        //     : next('/403');
        next();
    }
        // else if(!tokenStr) {
        //     next('/login');
        // role === to.meta.permission
        //     ? next()
        //     : next('/403');
        // next();
    // }
    else {
        next();
    }
});

export default router;
